﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace wRegPadron.Formularios
{
    public partial class Login : System.Web.UI.Page
    {
        protected bool Autenticar(string usuario, string pass)
        {
            bool estado = false;
            SqlConnection conn = new SqlConnection("Server=192.168.106.251; DataBase=dbTramiteMJM; User ID=sa; PWD=omega2");
            SqlCommand cmd = new SqlCommand("sp_s_WEB_M_MAES_USUA_Login", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataReader dr;
            try
            {
                cmd.Parameters.Add(new SqlParameter("@vUSUA_chLOGIN", usuario));
                cmd.Parameters.Add(new SqlParameter("@vUSUA_chPASSWORD", pass));
                cmd.Connection.Open();
                dr = cmd.ExecuteReader();
                if (dr.Read())
                    estado = true;
                cmd.Dispose();
                conn.Dispose();
            }
            catch (Exception ex)
            {
                cmd.Dispose();
                conn.Dispose();
            }
            return estado;
        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Unnamed3_Click(object sender, EventArgs e)
        {
            if (Autenticar(txtUsuario.Text, txtPass.Text))
            {
                Session.Add("usuarioAsis", txtUsuario.Text);
                Session.Add("PassAsis", txtPass.Text);
                Response.Redirect("Asistencia.aspx");
            }
        }
    }
}